# Maintainer: Smo <smo@xpra.org>

_realname=rencode
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.0.6
pkgrel=7
pkgdesc="Python module for fast (basic) object serialization similar to bencode (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/aresch/rencode'
msys2_references=(
  "cpe: cpe:/a:rencode_project:rencode"
  "purl: pkg:pypi/rencode"
)
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython0"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip)
source=("https://github.com/aresch/rencode/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        python-rencode-typecode-dos.patch)
sha256sums=('0ed61111f053ea37511da86ca7aed2a3cfda6bdaa1f54a237c4b86eea52f0733'
            '72046868ae82f7c9576fb9160bcf686cc893b5f104ee8b126c36466d06f21eb7')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    "${MINGW_PREFIX}"/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
